<?php
namespace app\api\controller;
header("Content-Type: text/html;charset=utf-8");
header('Access-Control-Allow-Origin:*');
use think\Controller;
use think\Db;
class Lists extends Controller
{
  public function advertise(){
    $advertise=Db::name('advertise_ck')->where('adstate',1)->where('adplaystate',1)->select();
    return json($advertise);
  }
//获取模版列表、详情
  public function template(){
    $tid=input('tid');
    if($tid==null)
      $template=Db::name('template_ck')->select();
    else
      $template=Db::name('template_ck')->where('tid',$tid)->select();
    return json($template);
   }

//获取文件列表、详情
    public function file(){
      $uid=input('uid');
      $fid=input('fid');
      if($fid==null)
        $file=Db::name('file_ck')->where('uid',$uid)->select();
      else
        $file=Db::name('file_ck')->where('fid',$fid)->select();
      return json($file);
    }

//获取终端设备列表、详情
    public function screen(){
      $sid=input('sid');
      if($sid==null)
        $screen=Db::name('screen_ck')->select();
      else
        $screen=Db::name('screen_ck')->where('sid',$sid)->select();
      return json($screen);
   }

//查询状态不同订单列表
//查询不同状态下某订单详情。
    public function order(){
      $uid=input('uid');
      $oid=input('oid');
      $ostate=input('ostate');
      $oplaystate=input('oplaystate');
      $opaystate=input('opaystate');
      if($oid==null) {
        if($oplaystate==null&&$opaystate==null){
        if($ostate==0){
          $order=Db::name('order_ck')->where('uid',$uid)->where('ostate',0)->select();//待审核
        }
        }
        if($ostate==null&&$opaystate==null){
        if($oplaystate==0){
          $order=Db::name('order_ck')->where('uid',$uid)->where('oplaystate',0)->select();//未播放
        }
        if($oplaystate==1){
          $order=Db::name('order_ck')->where('uid',$uid)->where('oplaystate',1)->select();//正在播放
        }
        if($oplaystate==2){
          $order=Db::name('order_ck')->where('uid',$uid)->where('oplaystate',2)->select();//结束播放
        }
        }
        if($ostate==null&&$oplaystate==null){
        if($opaystate==0){
          $order=Db::name('order_ck')->where('uid',$uid)->where('opaystate',0)->select();//未付款
        }
        if($opaystate==2){
          $order=Db::name('order_ck')->where('uid',$uid)->where('opaystate',2)->select();//用户取消
        }
        }
      }else{

        $order=Db::name('order_ck')->where('oid',$oid)->select();//详情
  
      }
      return json($order);
   }
//收藏模版列表，详情
    public function collect(){
      $uid=input('uid');
      $cid=input('cid');
      if($cid==null){
        $collect=Db::name('collecion_ck')->where('uid',$uid)->select();
        if($collect)
          return json($collect);
        else
          return json([
                        'error'=>'1',
                        'msg'=>'无收藏']);
      }else{
        $res=Db::name('collecion_ck')->where('uid',$uid)->where('cid',$cid)->find();
        $collect=Db::name('template_ck')->where('tid',$res['tid'])->select();
        if($collect)
          return json($collect);
        else
          return json(['error'=>'1']);
      }
    }
}